package com.litchishell.easy;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LitchiShell
 * @description: 题目：中序遍历二叉树
 * @create 2022-09-01
 */
public class Solution018 {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        addVal(root, result);
        return result;
    }

    private void addVal(TreeNode root, List<Integer> result) {
        if (root == null) {
            return;
        }
        addVal(root.left, result);
        result.add(root.val);
        addVal(root.right, result);
    }
}


class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
}
